package com.lokyiu.tutorial.java.exerisce3;

public class DrivingSimulate {
	private double newAcceleration,fuelComsuptionRate,fuelDuringTime,drivingTime;
	private Vehicle vehicle;
	private Road road;
	
	public DrivingSimulate(){
		
	}
	
	public DrivingSimulate(Vehicle vehicle, Road road){
		double newAcceleration = vehicle.getAcceleration() - road.getFriction();
		double fuelComsuptionRate = vehicle.weight / vehicle.horsePower;
		double fuelDuringTime = vehicle.getFuel() / fuelComsuptionRate ;
		this.newAcceleration=newAcceleration;
		this.fuelComsuptionRate=fuelComsuptionRate;
		this.fuelDuringTime=fuelDuringTime;
		this.vehicle=vehicle;
		this.road=road;
		this.StartEngine();
		this.displayTimeUsed();
	}
	
	public void StartEngine(){
		double drivingTime ;
		drivingTime = Math.sqrt(road.length / (vehicle.acceleration / road.friction));
		drivingTime = Math.round( drivingTime * 100.0) / 100.0;
		this.drivingTime=drivingTime;
	}
	
	public void displayTimeUsed(){
		if(drivingTime < 24){
			System.out.println("A Vehicle " + "(ID:"+ vehicle.number + ") " + "takes " + drivingTime 
					+ " seconds to pass through a " + road.length + "M long " + road.type + "Road" );
		}else{
			System.out.println("A Vehicle " + "(ID:"+ vehicle.number + ") " + "takes " + drivingTime 
					+ " seconds to pass through a " + road.length + "M long " + road.type + "Road !!Speeding!!" );
		}
	}
	
}
